from config import BASE_URL
from page.page_register import RegisterPage
from script import log
from tools import DriverTools


class TestRegister(object):

    def setup_method(self):
        # 打开浏览器
        driver = DriverTools.get_driver()
        # 输入网址
        driver.get(BASE_URL + "/common/member/reg")
        # 输入手机号、密码、验证码、...
        self.reg = RegisterPage(driver)

    def teardown_method(self):
        # 关闭浏览器
        DriverTools.quit_driver()

    def test01_reg_success(self):
        # 调用方法
        self.reg.register("13811110121", "Aa123456", "8888")
        # 打印结果
        result = self.reg.get_success_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert "注册成功" in result
        # 截图
        self.reg.get_shot("reg_success.png")

    # 注册失败（手机号已存在）
    def test02_reg_fail_phone_exist(self):
        # 调用方法
        self.reg.register("13811112040", "Aa123456", "8888")
        # 获取结果并打印
        result = self.reg.get_fail_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert "注册抢88现金" in result
        # 截图
        self.reg.get_shot("phone_exist.png")

    # 注册失败（密码错误）
    def test03_reg_fail_pwd_error(self):
        # 调用方法
        self.reg.register("13811112030", "12345678", "8888")
        # 获取结果并打印
        result = self.reg.get_fail_result()
        # print(result)
        log.info(f"执行结果：{result}")
        # 断言结果
        assert "注册抢88现金" in result
        # self.driver.get_screenshot_as_file(PATH+r"\img\pwd_error.png")
        self.reg.get_shot("pwd_error.png")


